package com.example.demo.controller;

import com.example.demo.service.StatusChangeService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RequestMapping("/api")
@RestController
public class StatusChangeController {
    @Resource
    StatusChangeService statusChangeService;

    @GetMapping("/ask")
    public ResponseEntity<Map<String,Object>> statusChange(@RequestParam("car_id") String car_id,@RequestParam("message_id") String message_id,@RequestParam("is_end") String is_end){
             Map<String,Object> status = new HashMap<>();
             status.put("carStatus",statusChangeService.change_statuses(Integer.parseInt(car_id),Integer.parseInt(message_id),Integer.parseInt(is_end)));
             //statusChangeService.changeStatus(Integer.parseInt(car_id),Integer.parseInt(message_id));
             //status.put("message_id",message_id);
             if(statusChangeService. checkMessage(Integer.parseInt(message_id))) {
                 statusChangeService.setMessageDone(Integer.parseInt(message_id));
                 status.put("DoneOrNot", 1);
             }
             else
                 status.put("DoneOrNot",0);
//             status.put("carStatus",statusChangeService.getStatus(Integer.parseInt(car_id)));
             return ResponseEntity.ok(status);
    }
}
